#include "tab_logging.h"
#include "client_print.h"

CTabLogging::CTabLogging(QWidget* pParent) :
	QWidget(pParent),
	mLayout(this),
	mIOSplitter(Qt::Vertical),
	mCltConsole(new QPlainTextEdit),
	mSrvConsole(new QPlainTextEdit)
{
	setupUiElements();
	setupActions();

	CClientPrint::setInstance(mCltConsole);
}

CTabLogging::~CTabLogging()
{
}

void CTabLogging::infoReceived(ELogLevel& pLogLevel, QString& pInfoMsg)
{
	QString lText("");

	switch(pLogLevel)
	{
		case LOG_WARN:
			lText.append("WARN | ");
			break;
		case LOG_ERR:
			lText.append("ERROR | ");
			break;
		case LOG_DEBUG:
		default:
			lText.append("DEBUG | ");
			break;
	}

	lText += pInfoMsg;
	mSrvConsole->appendPlainText(lText);
}

void CTabLogging::setupUiElements()
{
	mCltConsole->setReadOnly(true);
	mSrvConsole->setReadOnly(true);

	mIOSplitter.addWidget(mCltConsole);
	mIOSplitter.addWidget(mSrvConsole);
	
	mLayout.addWidget(&mIOSplitter);
}

void CTabLogging::setupActions()
{
}

void CTabLogging::startRequested()
{
	mCltConsole->appendPlainText("Start Signal sent.");
}

